package ipad.asia.controller;

import com.netflix.ribbon.proxy.annotation.Http;
import ipad.asia.config.FtpAdmin;
import ipad.asia.service.admin.AdminFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class Login {
    @Autowired
    private AdminFeign adminFeign;
    @RequestMapping("/admin/login")
    public String login(@RequestParam(value = "user",required = false)String user,
                        @RequestParam(value = "password",required = false)String password,
                        Model model, HttpServletRequest request){
        if(user==null){
            return "login";
        }else {
            if(adminFeign.login(user, password)){
                System.out.println(user);
                System.out.println("测试！！！！！！！");
                request.getSession().setAttribute("admin",user);
                return "redirect:/index";
            }else {
                model.addAttribute("message","密码错误！");
                return "login";
            }
        }
    }


}
